package com.example;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.Inet4Address;
import java.net.UnknownHostException;

/**
 * EnableAdminServer 要加上这个注解,用于启动监控页面
 */
@SpringBootApplication
@EnableAdminServer
// @EnableJdbcRepositories(basePackages = "com.example.entity")
public class SpringbootDemoApplication {
    static Logger logger = LoggerFactory.getLogger(SpringbootDemoApplication.class);

    public static void main(String[] args) throws UnknownHostException {

        ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringbootDemoApplication.class, args);
        ConfigurableEnvironment env = applicationContext.getEnvironment();
        String host = Inet4Address.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        logger.info("\n----------------------------------------------------------\n\t" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\thttp://localhost:{}\n\t" +
                        "External: \thttp://{}:{}\n\t" +
                        "SwaggerDoc: \thttp://{}:{}/swagger-ui/index.html\n\t" +
                        "Springboot Admin: \thttp://{}:{}\n\t" +
                        "----------------------------------------------------------",
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"),
                host, port,
                host, port,
                host,port+"/applications");
    }
}
